package tabou.app;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;

public class ActivityLancementManche extends Activity {
	private Button btnLancementManche;
	ControllerPartie controller;
	TextView tempsLancementManche;
	TextView score;
	
	 public void onCreate(Bundle savedInstanceState) {
	    controller = ControllerPartie.getControllerPartie();

		 super.onCreate(savedInstanceState);
	     setContentView(R.layout.lancementmanche);
	     
	     tempsLancementManche = (TextView)findViewById(R.id.TextViewLancementMancheTemps);
	     tempsLancementManche.setText(controller.getMinuteManche()+" min "+controller.getSecondeManche());
	     
        score = (TextView)findViewById(R.id.TextViewLancementMancheScoreBleu);
        score.setText(controller.getScoreBleu());
        
        score = (TextView)findViewById(R.id.TextViewLancementMancheScoreRose);
        score.setText(controller.getScoreRose());

	     btnLancementManche = (Button)findViewById(R.id.ButtonLancementManche);
	     btnLancementManche.setOnClickListener(new View.OnClickListener(){
	        public void onClick(View v)
	        {   
	            controller.mancheSuivante();
	        	Intent intManche = new Intent(v.getContext(), ActivityManche.class);
	        	finish();
	            //startActivityForResult(intManche,0);
	            startActivity(intManche);
	        }
        });
	     
	     //couleur bleue ou rose pour le fond
	     LinearLayout bilanMancheLayout=(LinearLayout)findViewById(R.id.lancementMancheLayout);
	    	if(controller.getPartie().getEquipeJouant()!=controller.getPartie().getEquipeBleu()){
	    		bilanMancheLayout.setBackgroundColor(getResources().getColor(R.color.bleuClair));
	    	}
	    	else{
	    		bilanMancheLayout.setBackgroundColor(getResources().getColor(R.color.roseClair));
	    	}
	 }
	 
	    public boolean onCreateOptionsMenu(Menu menu) {
	        MenuInflater inflater = getMenuInflater();
	        inflater.inflate(R.layout.menupartie, menu);
	        return true;
	    }
	    
	    public boolean onOptionsItemSelected(MenuItem item) {
	        switch (item.getItemId()) {
	            case R.id.icontext_quitter2: 
	            	finish();
	            break;
	        }
	        return true;
	    }
	    
	    /*public boolean onKeyDown(int keyCode, KeyEvent event)
	    {
	      switch(keyCode){
	     
	      case KeyEvent.KEYCODE_BACK :
	    	  AlertDialog.Builder builder = new AlertDialog.Builder(this);
	    	  builder.setMessage("Annuler la manche?")
	    	         .setCancelable(false)
	    	         .setPositiveButton("Oui", new DialogInterface.OnClickListener() {
	    	             public void onClick(DialogInterface dialog, int id) {
	    	            	 finish();
	    	             }
	    	         })
	    	         .setNegativeButton("Non", new DialogInterface.OnClickListener() {
	    	             public void onClick(DialogInterface dialog, int id) {
	    	                  dialog.cancel();
	    	             }
	    	         });
	    	  AlertDialog alert = builder.create();
	    	  alert.show();
	    	  return true;
	      }
	      
	      return false;
	    }*/
}
